import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';

// user.g.dart 将在我们运行生成命令后自动生成
part 'json_test_route.g.dart';

class JsonTestRoute extends StatefulWidget {
  const JsonTestRoute({Key? key}) : super(key: key);

  @override
  _JsonTestRouteState createState() => _JsonTestRouteState();
}

class _JsonTestRouteState extends State<JsonTestRoute> {
  @override
  Widget build(BuildContext context) {
    var user = User("tom", "123456@qq.com");
    return Scaffold(
      appBar: AppBar(
        title: const Text('Json Test'),
      ),
      body: Center(
        child: SelectableText(
          user.toJson().toString(),
        ),
      ),
    );
  }
}

@JsonSerializable()
class User {
  User(this.name, this.email);

  String name;

  String email;

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

  Map<String, dynamic> toJson() => _$UserToJson(this);
}
